﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;
using Huayou.UI.WebControls;
using System.Data;
using Huayou.Common;
using System.Data.SqlClient;
using HySoft.Cash.BaseClass;

namespace PayRoller.Manage.OrgInfo
{
    public class PaymentsComingdue : ParentPage, IRequiresSessionState
    {
        // Fields
        protected Huayou.UI.WebControls.DataGridTable dgdList;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected Label lblTip;
        public string OrgSid = "";
        protected TextBox txtParamstr;

        // Methods
        protected void bnSearch_Click(object sender, EventArgs e)
        {
            this.dgdList.DataBind();
        }

        protected void dgdList_CancelCommand(object source, DataGridCommandEventArgs e)
        {
            this.dgdList.EditItemIndex = -1;
            this.dgdList.DataBind();
        }

        protected void dgdList_DataBinding(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            TinvoicelistBN tbn = new TinvoicelistBN(this.Page);
            tbn.Filter = " OrgSid=" + base.Request["OrgSid"].ToString() + " and IsValid="+ (int)InvoiceStatuses.InitStatus;
            //tbn.Filter = " OrgSid=" + base.Request["OrgSid"].ToString() + " and IsValid!=3 and getdate()<InvoiceDate";
            tbn.Order = "Sid desc";
            dt = tbn.GetList();
            tbn.Dispose();
            tbn = null;
            CommonBasePage.SetPage(this.dgdList, dt);
            base.AddValue("pageno", Convert.ToString((int)(this.dgdList.CurrentPageIndex + 1)));
            this.txtParamstr.Text = base.PackPart(base.ParamValue);
        }

        protected void dgdList_EditCommand(object source, DataGridCommandEventArgs e)
        {
            this.dgdList.EditItemIndex = e.Item.ItemIndex;
            this.dgdList.DataBind();
        }

        protected void dgdList_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            this.dgdList.CurrentPageIndex = e.NewPageIndex;
            this.dgdList.DataBind();
        }

        protected void dgdList_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            int invoiceID = Convert.ToInt32(e.Item.Cells[0].Text);
            int orgID = Convert.ToInt32(e.Item.Cells[9].Text);
            decimal newPenalty = Convert.ToDecimal(((TextBox)e.Item.Cells[4].Controls[0]).Text);
            decimal newLateInterestCharges = Convert.ToDecimal(((TextBox)e.Item.Cells[5].Controls[0]).Text);

            decimal oldPenalty = Convert.ToDecimal(e.Item.Cells[6].Text);
            decimal oldLateInterestCharges = Convert.ToDecimal(e.Item.Cells[7].Text);

            Guid guid = new Guid(e.Item.Cells[8].Text);
            TinvoicelistBN.UpdateOtherFee(orgID, invoiceID, guid, newPenalty, oldPenalty, newLateInterestCharges, oldLateInterestCharges);

            //string text = e.Item.Cells[0].Text;
            //string str2 = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
            //string str3 = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
            //SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@Sid", text), new SqlParameter("@dPenalty", str2), new SqlParameter("@dInterestCharges", str3) };
            //SqlHelper.ExecuteNonQuery(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "UptInvoiceOtherFee", commandParameters);
            this.dgdList.EditItemIndex = -1;
            this.dgdList.DataBind();
        }

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.Request["OrgSid"] != null)
            {
                this.OrgSid = base.Request["OrgSid"].ToString();
            }
            if (!this.Page.IsPostBack)
            {
                base.ParamValue = base.UnPack();
                this.txtParamstr.Text = base.PackPart(base.ParamValue);
                string str = base.GetValue("pageno");
                if (str != null)
                {
                    this.dgdList.CurrentPageIndex = Convert.ToInt32(str) - 1;
                }
                this.dgdList.DataBind();
            }
            else
            {
                base.ParamValue = base.UnPackPart(this.txtParamstr.Text);
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
